//Class that represents a World

//Example <body onload="javascript:new World(MapEditor,1,["volcano","city"],["elves","dwarves"]);">

World = function(){

	var canvas;
	var gameTimer;
	var eventManager;
	var map;
	var ressource;
	
	//getter and setter
	World.prototype.setGameTimer = function(aGameTimer){
			gameTimer = aGameTimer;
	}
	World.prototype.getGameTimer = function(){
			return gameTimer;
	}
	
	//initialize
	World.prototype.initCanvas = function(){
			canvas = document.getElementById('main');
	}
	World.prototype.initEventManager = function(someEventManager){
			//someEventManager.initialize();
			eventManager = someEventManager;
	}
	World.prototype.initRessource = function(backgroundLibraries,monsterLibraries,someMapIndex){
			ressource = new Ressource();
			ressource.initialize(backgroundLibraries,monsterLibraries,someMapIndex);
	}
	World.prototype.initMap = function(res, can){
			map = new Map();
			map.initialize(res, can);
	}
	
	//getter
	World.prototype.getMap = function(){
			return map;
	}
	World.prototype.getRessource = function(){
			return ressource;
	}
	World.prototype.getEventManager = function(){
			return eventManager;
	}
	World.prototype.getCanvas = function(){
			return canvas;
	}
	
	var self = this;
	
	World.prototype.gameUpdate = function(){
		//TODO everything...
		//Can't be this wrong object...cause called from some other..
		self.getMap().update();
	}
	
}

//constructor
World.prototype.initialize = function(anEventManager,aMapIndex,someBackgroundLibraries,someMonsterLibraries){
	//asynchronous in this function huhum.... TO DO
	console.log("A World start initializing.");
	this.initCanvas();
	console.log("Canvas initialized.");
	this.initEventManager(anEventManager);
	console.log("Event Manager initialized.");
	this.initRessource(someBackgroundLibraries,someMonsterLibraries,aMapIndex);
	console.log("Ressources initialized.");
	this.initMap(this.getRessource(),this.getCanvas());
	console.log("Map initialized.");
	this.start();
	console.log("A World finish initializing.");
}

World.prototype.start = function(){
    this.setGameTimer(setInterval(this.gameUpdate,500));
}

